import json
from django.core.cache import cache as mem_cache
from celery import shared_task
from celery.task import periodic_task
from django import template
from stocksys import models as stocksys_models
from Library_WEB import settings
from stocksys.quant_tactics.RuleExcuter import RuleExcuter
from stocksys.quant_tactics.UserControl import UserControl, RealControl
from stocksys.sys_tasks.logic_function import DjangoTask, get_realtime_stock_content, workDay, stock_report, \
    onMarketOpen, beforeMarketOpen
from stocksys.views.data_logic import send_email_message


@periodic_task(run_every=60)
def stock_trade_60s():
    '''
    日内短线股票策略
    :return:
    '''
    if workDay():
        sysusers=stocksys_models.SysConf.objects.all()
        for sysuser in sysusers:
            main_rule=stocksys_models.RuleInfo.objects.get(sysuser.main_rule)
            context=RealControl(sysuser)
            rule_excuter = RuleExcuter(main_rule,context)
            rule_excuter.init_base_data()
            rule_excuter.init_excute()
            context=rule_excuter.init_function(context)
            if beforeMarketOpen():
                context=rule_excuter.before_market_open(context)
            if onMarketOpen():
                context=rule_excuter.market_open(context)


@periodic_task(run_every=60)
def futures_trade_60s():
    '''
    60秒超短线期货实盘策略
    :return:
    '''
